// 捕获引用或者移动所有权,可编译引用打印,捕获不可变引用的闭包
// fn main() {
//     let list = vec![1,2,3];
//     println!("Before defining closure: {:?}", list);

//     let only_borrows = || println!("From closure: {:?}", list);

//     println!("Before calling closure: {:?}", list);

//     only_borrows();
//     println!("After calling closure: {:?}", list);
// }

// fn main() {
//     let mut list = vec![1, 2, 3];
//     println!("Before defining closure: {:?}", list);

//     let mut borrows_mutably = || list.push(7);
//     //如果此处加入println会报错，因为可变引用没有结束
//     // println!("between calling closure: {:?}", list);
//     borrows_mutably();
//     println!("After calling closure: {:?}", list);
// }

//使用 move 来强制闭包为线程获取 list 的所有权

use std::thread;
fn main() {
    let list = vec![1, 2, 3];
    println!("Before defining closure: {:?}", list);

    thread::spawn(move || println!("From thread: {:?}", list))
        .join()
        .unwrap();
}
